package entity.JPanel;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

public class WelcomJPanel extends JPanel {
    private int width;
    private int height;
    BufferedImage bg;
    JLabel welcome_label = new JLabel("欢迎来到图书管理系统");

    public WelcomJPanel(int width, int height) {
        this.width = width;
        this.height = height;
        setLayout(new FlowLayout(FlowLayout.LEFT, 600, 200));
        initComponents();
        try {
            bg = ImageIO.read(WelcomJPanel.class.getClassLoader().getResourceAsStream("resources/images/Main.jpg"));
        } catch (Exception e) {
            System.out.println("NULL");
        }
    }

    public void paintComponent(Graphics g) {
        g.drawImage(bg, 0, 0, width, height, null);//绘制背景图片
    }

    private void initComponents() {
        //========welcome_label======
        Font font = new Font("楷体·", Font.PLAIN, 80);//定义
        welcome_label.setOpaque(true); //此句是重点，设置背景颜色必须先将它设置为不透明的，因为默认是透明的。
        welcome_label.setBackground(Color.GRAY);//设置背景颜色为red。
        welcome_label.setForeground(Color.cyan);//设置字体颜色为black。
        welcome_label.setFont(font);//设置字体和大小。
        add(welcome_label);
    }
}
